<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/adminlte/common-js.jsp"%>
  <%@ include file="/common/adminlte/common-css.jsp"%>	
  <title>WHQ | 基础平台</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/adminlte/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/adminlte/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
  		<br/>
		<ol class="breadcrumb bgblue">
			<li>
				<span class="label label-danger font14" >机构与用户管理 / 机构管理</span>
			</li>
		</ol>
		
    <!-- Main start -->

<section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              			<center>
              				<div class="btn-group">
								<button class="btn btn-info" type="button" onclick="toAddOrg();">增加机构</button>
				            	<button class="btn btn-info" type="button" onclick="alert('暂缓开通！');">增加子机构</button>
				            	<button class="btn btn-info" type="button" onclick="delOrg();">删除</button>
				            	<button class="btn btn-info" type="button" onclick="toEditOrg();">修改</button>
				            	<button class="btn btn-info" type="button" onclick="refresh();">刷新</button>
				            	<button class="btn btn-info" type="button">部门管理</button>
				            	<button class="btn btn-info" type="button">机构人员</button>
				            	<button class="btn btn-info" type="button">角色设置</button>
				            	<button class="btn btn-info" type="button">资源设置</button>	
			            	</div>					
            	</center>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example" class="table table-bordered table-hover">
                <thead>
                <tr>
                  <th>机构名称</th>
                  <th>机构标识</th>
                  <th>所属域</th>
                  <th>子节点数</th>
                  <th>英文全称</th>
                  <th>中文全称</th>
                  <th>当前状态</th>
                </tr>
                </thead>
              </table>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
  </div>
  <!-- /.content-wrapper -->
  <!-- foot start -->
  <%@include file="/common/adminlte/foot.jsp" %>
  <!-- foot start -->
  <!-- right start -->
  <%@include file="/common/adminlte/right.jsp" %>
  <!-- right start -->
  
<div class="modal fade" id="my_modal" tabindex="-1" role="dialog" data-toggle="modal" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="modal-title">
							<font color="red">机构信息</font>&nbsp;
						</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="orgForm">
							<input type="hidden" name="formToken" id="formToken" value="${formToken}">
							<input type="hidden" name="orgId" id="orgId" value="">
							<input type="hidden" name="fatherId" id="fatherId" value=""/>
							<input type="hidden" name="updateCount" id="updateCount" value=""/>
							<input type="hidden" name="sysEname" id="sysEname" value=""/>
							<input type="hidden" name="subCount" id="subCount" value=""/>
							
							 <div class="box-body" id="orgFormData">
							 
			                <div class="form-group">
			                  <label for="inputOrgCname" class="col-sm-2 control-label" >机构名称</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control"  name="orgCname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">机构标识</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control"  name="orgEname" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">机构代码</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" name="orgCode" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">联系人</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" name="linkMan" placeholder="">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">联系电话</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" name="phone" placeholder="">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">所在地区</label>
			                  <div class="col-sm-8">
			                    <input type="text" class="form-control" name="address" required placeholder="必填项">
			                  </div>
			                </div>
			                
			                <div class="form-group">
			                  <label class="col-sm-2 control-label">状态</label>
			                  <div class="col-sm-8">
			                    <input type="radio" checked="checked" value="1" name="orgStatus"> <i></i> 启用 
                                <input type="radio" value="0" name="orgStatus"> <i></i> 停用
			                  </div>
			                </div>
			                
			              </div>
			               <div class="box-footer">
			                <button type="button" class="btn btn-primary pull-left" onclick="cannel();">取消</button>
			                <button type="button" class="btn btn-primary pull-right" onclick="addOrg('orgForm');">提 交</button>
			              </div>
			              
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  
  
  
  
</body>



<script>
var search_url = "${ctx}/uct/org/org!data.action";
var add_url = "${ctx}/uct/org/save.action";
var del_url = "${ctx}/uct/org/del.action";
var view_url = "${ctx}/uct/org/getById.action";
var table;
$(function () {
	table = initTable();
	
	$('#example tbody').on('click','tr', function () {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }
	        else {
	            table.$('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     
     	//one
	 	//console.log($('tr.selected td').eq(1).html())
     	//two
	 	//console.log(table.$('tr.selected').find('td').eq(1).html());

	} );

	

	
	
  });

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){  
	cleanData('orgFormData');
}); 

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){  
	$.ajax({
	    type:'post',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
			 $('#formToken').val(myData);
	  	}
	});	
}); 

function cleanData(id){
	$(':input','#'+id)  
	 .not(':button, :submit, :reset, :hidden')  
	 .val('')  
	 //.removeAttr('checked')  
	 .removeAttr('selected'); 
}


function initTable(){
  var table = $('#example').DataTable({
		   "language": {"url": "${ctx}/plugins/datatables/dataTables_zh-CN.js"},//处理国际化
	        ajax: {
	        	"url":search_url,
	        	"dataSrc": ""
	        },
	        columns: [
	            { "data": "orgCname" },
	            { "data": "orgEname" },
	            { "data": "orgDomain" },
	            { "data": "subCount" },
	            { "data": "fullEname" },
	            { "data": "fullCname" },
	            { "data": "orgStatus" }
	        ],
	        fnCreatedRow: function(nRow, aData, iDataIndex) {
	               $('td:eq(0)', nRow).html("<span class='row-details row-details-close' data_id='" + aData.orgEname + "'></span>&nbsp;" + aData.orgCname);
	           },
	        fnRowCallback: function( nRow, aData, iDisplayIndex ) {
				if ( aData.subCount > 0  )
				{
					$('td', nRow).eq(3).html(aData.subCount);
				}else{
					$('td', nRow).eq(3).html('0');
				};
				if ( aData.orgStatus =='1' )
				{
					$('td', nRow).eq(6).html('<font color=blue>启用</font>');
				}else{
					$('td', nRow).eq(6).html('<font color=blue>停用</font>');
				};
				return nRow;
			}
	    });
  			return table;
  }
  
function getSelected(table){
	//console.log(table.rows('.selected').data());
	var obj =  table.rows('.selected').data();
	if(obj.length>0){
		return obj[0].orgId;
	}
}  
  
function toAddOrg(){
	$('#my_modal').modal('show');
}


function toEditOrg(){
	
	var orgId  = getSelected(table);
	if(orgId =="undefined"){
		alert("请先选中一条数据！");
		return;
	}else{
		$.ajax({
		    type:'post',
		    url:view_url,
		    data:{'id':orgId},
		    dataType:'json',
		    success: function(myData){
				 FormUtil.fillData("#orgForm", myData);
				 $('#my_modal').modal('show');
		  	}
		});	
	}
	
	
	//$('#my_modal').modal('show');
	
	
	
}

function delOrg(){
	var orgId  = getSelected(table);
	if(orgId =="undefined"){
		alert("请先选中一条数据！");
		return;
	}else{
		$.ajax({
		    type:'post',
		    url:del_url,
		    data:{'id':orgId},
		    dataType:'json',
		    success: function(myData){
		    	if(myData.flag=='T'){
		    		alert("删除成功！");
		    		refresh();
		    	}

		  	}
		});	
	}

	
}

function addOrg(formId){
	
	if(!$("#" + formId)[0].checkValidity()){
		alert("请先完善必输项和必选项！");
		return ;
	}
	
	$.ajax({
	    type:'post',
	    url:add_url,
	    data:$("#"+formId).serialize(),
	    dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
	    	if(myData.flag=='T'){
	    		alert("添加成功！");
	    		$('#my_modal').modal('hide');
	    		refresh();
	    	}

	  	}
	});	
	
	
}

function cannel(){
	$('#my_modal').modal('hide');

}

function refresh(){
    //window.location.reload();
    table.ajax.reload();
}


</script>




</html>
